package com.hellobike.haxing.modules.pms.product.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hellobike.haxing.common.annotation.AutoLog;
import com.hellobike.haxing.common.system.base.controller.BaseController;
import com.hellobike.haxing.common.system.query.QueryGenerator;
import com.hellobike.haxing.common.system.vo.LoginUser;
import com.hellobike.haxing.common.vo.Result;
import com.hellobike.haxing.modules.address.util.Convert2KV;
import com.hellobike.haxing.modules.purchase.common.TimerUtil;
import com.hellobike.haxing.modules.purchase.service.ITPurchaseOrderDetailService;
import com.hellobike.haxing.modules.purchase.service.ITPurchaseProService;
import com.hellobike.haxing.modules.supplier.dto.TSupplierClProRecordDto;
import com.hellobike.haxing.modules.supplier.dto.TSupplierClProRecordInfoDto;
import com.hellobike.haxing.modules.supplier.entity.TSupplierClPro;
import com.hellobike.haxing.modules.supplier.entity.TSupplierClProRecord;
import com.hellobike.haxing.modules.supplier.entity.TSupplierInfo;
import com.hellobike.haxing.modules.supplier.mapper.TSupplierClassificationMapper;
import com.hellobike.haxing.modules.supplier.service.ITSupplierClProRecordService;
import com.hellobike.haxing.modules.supplier.service.ITSupplierClProService;
import com.hellobike.haxing.modules.supplier.service.ITSupplierInfoService;
import com.hellobike.haxing.modules.supplier.util.BeanUtils;
import com.hellobike.haxing.modules.wms.utils.ListUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;

/**
 * @Description: 供应商商品表
 * @Author: haxing-boot
 * @Date: 2020-01-15
 * @Version: V1.0
 */
@RestController
@RequestMapping("/pms/tSupplierClPro")
@Slf4j
public class TPMSSupplierClProController extends BaseController<TSupplierClPro, ITSupplierClProService> {
    @Autowired
    private ITSupplierClProService tSupplierClProService;

    @Autowired
    private ITSupplierClProRecordService itSupplierClProRecordService;

    @Autowired
    private ITPurchaseOrderDetailService itPurchaseOrderDetailService;

    @Autowired
    private ITPurchaseProService itPurchaseProService;

    @Autowired
    private ITSupplierInfoService tSupplierInfoService;

    @Autowired
    private TSupplierClassificationMapper supplierClassificationMapper;

    /**
     * 分页列表查询
     *
     * @param tSupplierClPro
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "供应商商品表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(TSupplierClPro tSupplierClPro,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<TSupplierClPro> queryWrapper = QueryGenerator.initQueryWrapper(tSupplierClPro, req.getParameterMap());
        Long supplierId = getSupplierId();
        if (supplierId == null) {
            return Result.error("用户不存在");
        }
        queryWrapper.eq("supplier_id", supplierId);
        Page<TSupplierClPro> page = new Page<TSupplierClPro>(pageNo, pageSize);
        IPage<TSupplierClPro> pageList = tSupplierClProService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

    private Long getSupplierId() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            return null;
        }
        QueryWrapper<TSupplierInfo> tSupplierInfoQueryWrapper = new QueryWrapper<>();
        tSupplierInfoQueryWrapper.eq("mobile", sysUser.getPhone());
        TSupplierInfo tSupplierInfo = tSupplierInfoService.getOne(tSupplierInfoQueryWrapper);
        if (tSupplierInfo == null) {
            return null;
        }
        return tSupplierInfo.getId();
    }

    /**
     * 通过id生成供应商信息
     *
     * @param json
     * @return
     */
    @PostMapping(value = "/getBySupplierId")
    public Result<?> getBySupplierId(@RequestBody JSONObject json) {
        Long headerId = json.getLong("headerId");
        return Result.ok(tSupplierClProService.getBySupplierId(headerId));
    }

    /**
     * 通过id生成供应商信息
     *
     * @param json
     * @return
     */
    @PostMapping(value = "/getByRecordSupplierId")
    public Result<?> getByRecordSupplierId(@RequestBody JSONObject json) {
        Long headerId = json.getLong("headerId");
        return Result.ok(itSupplierClProRecordService.getBySupplierId(headerId));
    }

    /**
     * 通过id生成供应商信息
     *
     * @param json
     * @return
     */
    @PostMapping(value = "/getSupplier4Price")
    public Result<?> getSupplier4Price(@RequestBody JSONObject json) {
        QueryWrapper<TSupplierClPro> queryWrapper = new QueryWrapper<>();
        Long headerId = json.getLong("headerId");
        return Result.ok(tSupplierClProService.getById(headerId));
    }

    /**
     * 通过id查询
     *
     * @param json
     * @return
     */
    @PostMapping(value = "/initSuppliersBySku")
    public Result<?> initSuppliersBySku(@RequestBody JSONObject json) {
        Long headerId = json.getLong("headerId");
        QueryWrapper<TSupplierClPro> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sku_id", headerId);
        List<TSupplierClPro> tSupplierClPros = tSupplierClProService.list(queryWrapper);
        if (tSupplierClPros == null || tSupplierClPros.size() < 1) {
            return Result.error("未找到对应数据");
        }
        List<TSupplierClPro> res = tSupplierClPros.stream().collect(collectingAndThen(
                toCollection(() -> new TreeSet<>(comparing(n -> n.getId()))), ArrayList::new)
        );
        return Result.ok(Convert2KV.SupplierInfo2kv(res));
    }


    /**
     * 添加
     *
     * @param tSupplierClPro
     * @return
     */
    @AutoLog(value = "供应商商品表-添加", operateType = 2)
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody TSupplierClPro tSupplierClPro) {
        tSupplierClProService.save(tSupplierClPro);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑
     *
     * @param tSupplierClPro
     * @return
     */
    @AutoLog(value = "供应商商品表-编辑", operateType = 3)
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody TSupplierClPro tSupplierClPro) {
        tSupplierClProService.updateById(tSupplierClPro);
        return Result.ok("编辑成功!");
    }

    /**
     * 编辑
     *
     * @param tSupplierClPro
     * @return
     */
    @AutoLog(value = "供应商商品记录表-编辑", operateType = 3)
    @PutMapping(value = "/editBySupplier")
    public Result<?> editBySupplier(@RequestBody TSupplierClPro tSupplierClPro) {

        QueryWrapper<TSupplierClPro> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", tSupplierClPro.getId());
        TSupplierClPro oldOne = tSupplierClProService.getOne(queryWrapper);
        if (oldOne != null && oldOne.getSupplierPrice() != null && tSupplierClPro.getSupplierPrice() != null && oldOne.getSupplierPrice().compareTo(tSupplierClPro.getSupplierPrice()) == 0) {
            tSupplierClProService.updateById(tSupplierClPro);
            // 同步供应价到pro表
            itPurchaseProService.updatePurchaseProFromClp(tSupplierClPro.getSkuId(), tSupplierClPro.getSupplierPrice(), tSupplierClPro.getSupplyVolume());
        } else {
            Integer week = TimerUtil.getWeekOfDate(new Date());
            if (!week.equals(4)) {
                return Result.error("单价每周四可修改!");
            }


//		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//		String createTime = simpleDateFormat.format(new Date());
//
//		QueryWrapper<TSupplierClProRecord> queryWrapper = new QueryWrapper<>();
//		queryWrapper.eq("supplier_id", tSupplierClPro.getSupplierId());
//		queryWrapper.eq("sku_id", tSupplierClPro.getSkuId());
//		queryWrapper.ge("create_time", createTime);
//		int cloProRecord = itSupplierClProRecordService.count(queryWrapper);
//		if(cloProRecord > 0){
//			return Result.error("每周四更新一次");
//		}

            TSupplierClProRecord tSupplierClProRecord = new TSupplierClProRecord();
            BeanUtils.copyProperties(tSupplierClPro, tSupplierClProRecord);
            tSupplierClProRecord.setCreateTime(new Date());
            tSupplierClProRecord.setUpdateTime(new Date());
            itSupplierClProRecordService.save(tSupplierClProRecord);
            tSupplierClProService.updateById(tSupplierClPro);
//		 更新 供应商未确认的商品的供应量
//		itPurchaseOrderDetailService.updateBySkuIdAndSupplier(tSupplierClPro.getSkuId(),tSupplierClPro.getSupplyVolume());
            // 同步供应价到pro表
            itPurchaseProService.updatePurchaseProFromClp(tSupplierClPro.getSkuId(), tSupplierClPro.getSupplierPrice(), tSupplierClPro.getSupplyVolume());
        }
        return Result.ok("编辑成功!");
    }

    /**
     * 通过id查询
     *
     * @param json
     * @return
     */
    @PostMapping(value = "/getClpRecords")
    public Result<?> getClpRecords(@RequestBody JSONObject json) {
        Long headerId = json.getLong("headerId");
        if (headerId == null) {
            return Result.error("未找到对应数据");
        }
        TSupplierClProRecordInfoDto resInfo = new TSupplierClProRecordInfoDto();
        List<String> clpFields = new ArrayList<>();
        List<TSupplierClProRecordDto> resDto = new ArrayList<>();
        List<TSupplierClProRecord> tSupplierClProRecords = itSupplierClProRecordService.getDupClPro(headerId);
        if (ListUtil.isNotEmpty(tSupplierClProRecords)) {
            for (TSupplierClProRecord supplier : tSupplierClProRecords) {
                clpFields.add(supplier.getSupplierName());
//				if(clpFields.isEmpty()){
//					clpFields = "'"+supplier.getSupplierName() +"'";
//				}else{
//					clpFields = clpFields + ",'" +supplier.getSupplierName() + "'";
//				}

                QueryWrapper<TSupplierClProRecord> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("sku_id", headerId);
                queryWrapper.eq("supplier_id", supplier.getSupplierId());
                queryWrapper.orderByDesc("create_time");
                queryWrapper.last("limit 10");
                List<TSupplierClProRecord> tSupplierClPros = itSupplierClProRecordService.list(queryWrapper);
                if (ListUtil.isNotEmpty(tSupplierClPros)) {
                    Integer supplyVolume1 = null;
                    BigDecimal supplierPrice1 = null;
                    Integer supplyVolume2 = null;
                    BigDecimal supplierPrice2 = null;
                    Integer supplyVolume3 = null;
                    BigDecimal supplierPrice3 = null;
                    Integer supplyVolume4 = null;
                    BigDecimal supplierPrice4 = null;
                    Integer supplyVolume5 = null;
                    BigDecimal supplierPrice5 = null;
                    Integer supplyVolume6 = null;
                    BigDecimal supplierPrice6 = null;
                    Integer supplyVolume7 = null;
                    BigDecimal supplierPrice7 = null;
                    TSupplierClProRecordDto resRecords = new TSupplierClProRecordDto();
                    for (TSupplierClProRecord record : tSupplierClPros) {
                        try {
                            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                            Date dateNow = df.parse(df.format(new Date()));
                            Date dateRes = df.parse(df.format(record.getCreateTime()));
                            Long weeks = (dateNow.getTime() - dateRes.getTime()) / (7 * 24 * 60 * 60 * 1000);
                            if (weeks != null && weeks == 0) {
                                if (supplyVolume7 == null && supplierPrice7 == null) {
                                    supplyVolume7 = record.getSupplyVolume();
                                    supplierPrice7 = record.getSupplierPrice();
                                }
                            } else if (weeks != null && weeks == 1) {
                                if (supplyVolume6 == null && supplierPrice6 == null) {
                                    supplyVolume6 = record.getSupplyVolume();
                                    supplierPrice6 = record.getSupplierPrice();
                                }
                                if (supplyVolume7 == null && supplierPrice7 == null) {
                                    supplyVolume7 = record.getSupplyVolume();
                                    supplierPrice7 = record.getSupplierPrice();
                                }
                            } else if (weeks != null && weeks == 2) {
                                if (supplyVolume5 == null && supplierPrice5 == null) {
                                    supplyVolume5 = record.getSupplyVolume();
                                    supplierPrice5 = record.getSupplierPrice();
                                }
                                if (supplyVolume6 == null && supplierPrice6 == null) {
                                    supplyVolume6 = record.getSupplyVolume();
                                    supplierPrice6 = record.getSupplierPrice();
                                }
                                if (supplyVolume7 == null && supplierPrice7 == null) {
                                    supplyVolume7 = record.getSupplyVolume();
                                    supplierPrice7 = record.getSupplierPrice();
                                }
                            } else if (weeks != null && weeks == 3) {
                                if (supplyVolume4 == null && supplierPrice4 == null) {
                                    supplyVolume4 = record.getSupplyVolume();
                                    supplierPrice4 = record.getSupplierPrice();
                                }
                                if (supplyVolume5 == null && supplierPrice5 == null) {
                                    supplyVolume5 = record.getSupplyVolume();
                                    supplierPrice5 = record.getSupplierPrice();
                                }
                                if (supplyVolume6 == null && supplierPrice6 == null) {
                                    supplyVolume6 = record.getSupplyVolume();
                                    supplierPrice6 = record.getSupplierPrice();
                                }
                                if (supplyVolume7 == null && supplierPrice7 == null) {
                                    supplyVolume7 = record.getSupplyVolume();
                                    supplierPrice7 = record.getSupplierPrice();
                                }
                            } else if (weeks != null && weeks == 4) {
                                if (supplyVolume3 == null && supplierPrice3 == null) {
                                    supplyVolume3 = record.getSupplyVolume();
                                    supplierPrice3 = record.getSupplierPrice();
                                }
                                if (supplyVolume4 == null && supplierPrice4 == null) {
                                    supplyVolume4 = record.getSupplyVolume();
                                    supplierPrice4 = record.getSupplierPrice();
                                }
                                if (supplyVolume5 == null && supplierPrice5 == null) {
                                    supplyVolume5 = record.getSupplyVolume();
                                    supplierPrice5 = record.getSupplierPrice();
                                }
                                if (supplyVolume6 == null && supplierPrice6 == null) {
                                    supplyVolume6 = record.getSupplyVolume();
                                    supplierPrice6 = record.getSupplierPrice();
                                }
                                if (supplyVolume7 == null && supplierPrice7 == null) {
                                    supplyVolume7 = record.getSupplyVolume();
                                    supplierPrice7 = record.getSupplierPrice();
                                }
                            } else if (weeks != null && weeks == 5) {
                                if (supplyVolume2 == null && supplierPrice2 == null) {
                                    supplyVolume2 = record.getSupplyVolume();
                                    supplierPrice2 = record.getSupplierPrice();
                                }
                                if (supplyVolume3 == null && supplierPrice3 == null) {
                                    supplyVolume3 = record.getSupplyVolume();
                                    supplierPrice3 = record.getSupplierPrice();
                                }
                                if (supplyVolume4 == null && supplierPrice4 == null) {
                                    supplyVolume4 = record.getSupplyVolume();
                                    supplierPrice4 = record.getSupplierPrice();
                                }
                                if (supplyVolume5 == null && supplierPrice5 == null) {
                                    supplyVolume5 = record.getSupplyVolume();
                                    supplierPrice5 = record.getSupplierPrice();
                                }
                                if (supplyVolume6 == null && supplierPrice6 == null) {
                                    supplyVolume6 = record.getSupplyVolume();
                                    supplierPrice6 = record.getSupplierPrice();
                                }
                                if (supplyVolume7 == null && supplierPrice7 == null) {
                                    supplyVolume7 = record.getSupplyVolume();
                                    supplierPrice7 = record.getSupplierPrice();
                                }
                            } else if (weeks != null && weeks == 6) {
                                if (supplyVolume1 == null && supplierPrice1 == null) {
                                    supplyVolume1 = record.getSupplyVolume();
                                    supplierPrice1 = record.getSupplierPrice();
                                }
                                if (supplyVolume2 == null && supplierPrice2 == null) {
                                    supplyVolume2 = record.getSupplyVolume();
                                    supplierPrice2 = record.getSupplierPrice();
                                }
                                if (supplyVolume3 == null && supplierPrice3 == null) {
                                    supplyVolume3 = record.getSupplyVolume();
                                    supplierPrice3 = record.getSupplierPrice();
                                }
                                if (supplyVolume4 == null && supplierPrice4 == null) {
                                    supplyVolume4 = record.getSupplyVolume();
                                    supplierPrice4 = record.getSupplierPrice();
                                }
                                if (supplyVolume5 == null && supplierPrice5 == null) {
                                    supplyVolume5 = record.getSupplyVolume();
                                    supplierPrice5 = record.getSupplierPrice();
                                }
                                if (supplyVolume6 == null && supplierPrice6 == null) {
                                    supplyVolume6 = record.getSupplyVolume();
                                    supplierPrice6 = record.getSupplierPrice();
                                }
                                if (supplyVolume7 == null && supplierPrice7 == null) {
                                    supplyVolume7 = record.getSupplyVolume();
                                    supplierPrice7 = record.getSupplierPrice();
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    resRecords.setId(tSupplierClPros.get(0).getId());
                    resRecords.setSupplierPrice1(supplierPrice1 == null ? new BigDecimal(0) : supplierPrice1);
                    resRecords.setSupplierPrice2(supplierPrice2 == null ? new BigDecimal(0) : supplierPrice2);
                    resRecords.setSupplierPrice3(supplierPrice3 == null ? new BigDecimal(0) : supplierPrice3);
                    resRecords.setSupplierPrice4(supplierPrice4 == null ? new BigDecimal(0) : supplierPrice4);
                    resRecords.setSupplierPrice5(supplierPrice5 == null ? new BigDecimal(0) : supplierPrice5);
                    resRecords.setSupplierPrice6(supplierPrice6 == null ? new BigDecimal(0) : supplierPrice6);
                    resRecords.setSupplierPrice7(supplierPrice7 == null ? new BigDecimal(0) : supplierPrice7);
                    resRecords.setSupplyVolume1(supplyVolume1 == null ? 0 : supplyVolume1);
                    resRecords.setSupplyVolume2(supplyVolume2 == null ? 0 : supplyVolume2);
                    resRecords.setSupplyVolume3(supplyVolume3 == null ? 0 : supplyVolume3);
                    resRecords.setSupplyVolume4(supplyVolume4 == null ? 0 : supplyVolume4);
                    resRecords.setSupplyVolume5(supplyVolume5 == null ? 0 : supplyVolume5);
                    resRecords.setSupplyVolume6(supplyVolume6 == null ? 0 : supplyVolume6);
                    resRecords.setSupplyVolume7(supplyVolume7 == null ? 0 : supplyVolume7);
                    resRecords.setSkuId(tSupplierClPros.get(0).getSkuId());
                    resRecords.setSkuName(tSupplierClPros.get(0).getSkuName());
                    resRecords.setSupplierId(tSupplierClPros.get(0).getSupplierId());
                    resRecords.setSupplierName(tSupplierClPros.get(0).getSupplierName());
                    resDto.add(resRecords);
                }
            }
        }

        List<String> clpInfos = new ArrayList<>();
        String clpInfo = new String();
        if (ListUtil.isNotEmpty(resDto)) {
            for (int i = 0; i < 7; i++) {
                if (i == 0) {
//					String clpInfo= new String();
                    clpInfo = "[{type:'第七周', ";
                    int j = 0;
                    for (TSupplierClProRecordDto info : resDto) {
                        if (j == 0) {
                            clpInfo = clpInfo + info.getSupplierName() + ":" + info.getSupplierPrice1();
                        } else {
                            clpInfo = clpInfo + "," + info.getSupplierName() + ":" + info.getSupplierPrice1();
                        }
                        j++;
                    }
                    clpInfo = clpInfo + "}";
                    clpInfos.add(clpInfo);
                } else if (i == 1) {
//					String clpInfo= new String();
                    clpInfo = clpInfo + ",{type:'第六周', ";
                    int j = 0;
                    for (TSupplierClProRecordDto info : resDto) {
                        if (j == 0) {
                            clpInfo = clpInfo + info.getSupplierName() + ":" + info.getSupplierPrice2();
                        } else {
                            clpInfo = clpInfo + "," + info.getSupplierName() + ":" + info.getSupplierPrice2();
                        }
                        j++;
                    }
                    clpInfo = clpInfo + "}";
                    clpInfos.add(clpInfo);
                } else if (i == 2) {
//					String clpInfo= new String();
                    clpInfo = clpInfo + ",{type:'第五周', ";
                    int j = 0;
                    for (TSupplierClProRecordDto info : resDto) {
                        if (j == 0) {
                            clpInfo = clpInfo + info.getSupplierName() + ":" + info.getSupplierPrice3();
                        } else {
                            clpInfo = clpInfo + "," + info.getSupplierName() + ":" + info.getSupplierPrice3();
                        }
                        j++;
                    }
                    clpInfo = clpInfo + "}";
                    clpInfos.add(clpInfo);
                } else if (i == 3) {
//					String clpInfo= new String();
                    clpInfo = clpInfo + ",{type:'第四周', ";
                    int j = 0;
                    for (TSupplierClProRecordDto info : resDto) {
                        if (j == 0) {
                            clpInfo = clpInfo + info.getSupplierName() + ":" + info.getSupplierPrice4();
                        } else {
                            clpInfo = clpInfo + "," + info.getSupplierName() + ":" + info.getSupplierPrice4();
                        }
                        j++;
                    }
                    clpInfo = clpInfo + "}";
                    clpInfos.add(clpInfo);
                } else if (i == 4) {
//					String clpInfo= new String();
                    clpInfo = clpInfo + ",{type:'第三周', ";
                    int j = 0;
                    for (TSupplierClProRecordDto info : resDto) {
                        if (j == 0) {
                            clpInfo = clpInfo + info.getSupplierName() + ":" + info.getSupplierPrice5();
                        } else {
                            clpInfo = clpInfo + "," + info.getSupplierName() + ":" + info.getSupplierPrice5();
                        }
                        j++;
                    }
                    clpInfo = clpInfo + "}";
                    clpInfos.add(clpInfo);
                } else if (i == 5) {
//					String clpInfo= new String();
                    clpInfo = clpInfo + ",{type:'第二周', ";
                    int j = 0;
                    for (TSupplierClProRecordDto info : resDto) {
                        if (j == 0) {
                            clpInfo = clpInfo + info.getSupplierName() + ":" + info.getSupplierPrice6();
                        } else {
                            clpInfo = clpInfo + "," + info.getSupplierName() + ":" + info.getSupplierPrice6();
                        }
                        j++;
                    }
                    clpInfo = clpInfo + "}";
                    clpInfos.add(clpInfo);
                } else if (i == 6) {
//					String clpInfo= new String();
                    clpInfo = clpInfo + ",{type:'第一周', ";
                    int j = 0;
                    for (TSupplierClProRecordDto info : resDto) {
                        if (j == 0) {
                            clpInfo = clpInfo + info.getSupplierName() + ":" + info.getSupplierPrice7();
                        } else {
                            clpInfo = clpInfo + "," + info.getSupplierName() + ":" + info.getSupplierPrice7();
                        }
                        j++;
                    }
                    clpInfo = clpInfo + "}]";
                    clpInfos.add(clpInfo);
                }
            }
        }
        resInfo.setClpFields(clpFields);
        resInfo.setClpInfo(JSON.parseArray(clpInfo));
        resInfo.setTSupplierClProRecordDtos(resDto);
        return Result.ok(resInfo);
    }


    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "供应商商品表-删除", operateType = 4)
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) Long id) {
        tSupplierClProService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "供应商商品表-批量删除", operateType = 4)
    @DeleteMapping(value = "/deleteBatch")
    public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.tSupplierClProService.removeByIds(Arrays.asList(ids.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()));
        return Result.ok("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/queryById")
    public Result<?> queryById(@RequestParam(name = "id", required = true) Long id) {
        TSupplierClPro tSupplierClPro = tSupplierClProService.getById(id);
        if (tSupplierClPro == null) {
            return Result.error("未找到对应数据");
        }
        return Result.ok(tSupplierClPro);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param tSupplierClPro
     */
    @AutoLog(value = "供应商商品表-导出excel", operateType = 6)
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, TSupplierClPro tSupplierClPro) {
        return super.exportXls(request, tSupplierClPro, TSupplierClPro.class, "供应商商品表");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @AutoLog(value = "供应商商品表-导入excel", operateType = 5)
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, TSupplierClPro.class);
    }

}
